package com.gxa.medical.controller;

import com.gxa.medical.exception.BusinessException;
import com.gxa.medical.pojo.DoctorAccount;
import com.gxa.medical.service.DoctorAccountService;
import com.gxa.medical.util.JsonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Yang Kai
 * @Date: 2022/06/09/10:12
 * @Description:
 */

@RestController
@RequestMapping("/doctor")
public class DoctorAccountController {
  @Autowired
  private DoctorAccountService doctorAccountService;
  @ApiOperation("医生注册")
  @PostMapping("/register")
  public Map insertRegister(@RequestBody DoctorAccount doctorAccount,
                            @RequestParam("captcha") String captcha,
                            @ApiIgnore HttpSession session) throws BusinessException {
    JsonResult jsonResult = new JsonResult();
    String captcha1 = (String) session.getAttribute("captcha");
    if(captcha.equals(captcha1)){
      Integer integer = doctorAccountService.insertDoctorAccount(doctorAccount);
      jsonResult.setCode("200");
      jsonResult.setMsg("验证码正确");
    }else {
      jsonResult.setCode("1");
      jsonResult.setMsg("验证码不正确");
    }
    return jsonResult.getResultMap();
  }
}
